package com.ruoyi.framework.web.service;

import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service("fmt")
public class FormatService {

    public String formatDecimal(String value){
        if(StringUtils.isBlank(value) || !NumberUtils.isCreatable(value)){
            return value;
        }else{
            BigDecimal decimal = new BigDecimal(value).stripTrailingZeros();
            if(decimal.equals(BigDecimal.ZERO)){
                return "";
            }
            return decimal.toPlainString();
        }
    }
}
